<template>
  <div class="user-panel">
    <el-form :model="user" label-width="120px">
      <el-form-item label="用户名称">
        <el-input v-model="user.userName" class="user-input"></el-input>
      </el-form-item>
      <el-form-item label="登录帐号名">
        <el-input v-model="user.loginName" class="user-input"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input v-model="user.pwd" class="user-input"></el-input>
      </el-form-item>
      <el-form-item label="邮箱">
        <el-input v-model="user.email" class="user-input"></el-input>
      </el-form-item>
      <el-form-item label="电话号码">
        <el-input v-model="user.tel" class="user-input"></el-input>
      </el-form-item>
      <el-form-item label="所属公司">
        <el-select v-model="user.department" filterable placeholder="请选择" class="user-input">
          <el-option v-for="company in companyList" :key="1" :label="company.name" :value="company.rCompanyId"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="">
        <el-button type="primary" @click="addUser">确定</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  export default {
    name: "user",
    data() {
      return {
        companyList: []
      }
    },
    props: {
      user: Object,
      state: Number,
      isUser: Boolean
    },
    methods: {
      //查询公司列表
      queryCompanys() {
        var that = this;
        this.$http.post("/validComanyList.shtml", "param=" + JSON.stringify({companyId: ""})).then(data => {
          console.log(data);
          that.companyList = data.data
        })
      },
      //添加用户
      addUser() {
        var that = this, msg = this.state ?'添加' :'修改', url = this.state ?'/addUser.shtml' :'/updateUser.shtml'
        this.$http.post(url, "param=" + JSON.stringify(this.user)).then(data => {
          if (data.code == 200) {
            that.$notify({
              title: '成功',
              message: data.msg || (msg + '用户成功'),
              type: 'success'
            });
            that.$parent.close()
          } else {
            that.$notify({
              title: '失败',
              message: data.msg || (msg + '用户失败'),
              type: 'error'
            });
          }
        })
      }
    },
    beforeRouteEnter(to, from, next) {
      next(vm => {
        
      })
    },
    created() {
      this.queryCompanys();
    }
  }
</script>

<style>
  .user-panel .user-input {
    width: 220px;
  }
</style>